﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;

namespace Entity
{
    public class THAMSO
    {
        
        private String TENTHAMSO;
        private float GIATRI;

        public String tenThamSo
        {
            get { return TENTHAMSO; }
            set { TENTHAMSO = value; }
        }

        public float giatri
        {
            get { return GIATRI; }
            set { GIATRI = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        DataBaseAccess dataBaseAccess = new DataBaseAccess();

        public void hienthi_ThamSo(DataGridView dtgThamSo)
        {
            DataTable dataTable = new DataTable();
            dataTable = dataBaseAccess.getDataTable("SELECT * FROM THAMSO");
            dtgThamSo.DataSource = dataTable;
        }

        public void capnhat_ThamSo(THAMSO thamso)
        {
            String excuteString = "UPDATE THAMSO SET GIATRI =" + thamso.giatri + 
                                          "WHERE TENTHAMSO ='" + thamso.tenThamSo + "'";
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public int tietchuan_tinchi()
        {
            int a = 0;
            String excuteString = "SELECT GIATRI FROM THAMSO WHERE TENTHAMSO ='TietChuanTrenTinChi'";
            a = Convert.ToInt16(dataBaseAccess.excuteScalar(excuteString));
            return a;
        }

        public float heso_siso(int siso)
        {
            float heso = 0;
            if (siso < 80)
            {
                String excuteString = "SELECT GIATRI FROM THAMSO WHERE TENTHAMSO='SiSoDuoi80'";
                heso= (float)Convert.ToDouble(dataBaseAccess.excuteScalar(excuteString));
            } 
            else if (siso < 140)
            {
                String excuteString = "SELECT GIATRI FROM THAMSO WHERE TENTHAMSO='SiSoTu80Den139'";
                heso = (float)Convert.ToDouble(dataBaseAccess.excuteScalar(excuteString));
            }
            else 
            {
                String excuteString = "SELECT GIATRI FROM THAMSO WHERE TENTHAMSO='SiSoTu140Den179'";
                heso = (float)Convert.ToDouble(dataBaseAccess.excuteScalar(excuteString));
            }
            return heso;          
        }
        public int tietchuan_ChuNhiem()
        {
            int a = 0;
            String excuteString = "SELECT GIATRI FROM THAMSO WHERE TENTHAMSO ='TietChuanChoChuNhiem'";
            a = Convert.ToInt16(dataBaseAccess.excuteScalar(excuteString));
            return a;
        }

        public float tien_TietChuan()
        {
            float a = 0;
            String excuteString = "SELECT GIATRI FROM THAMSO WHERE TENTHAMSO ='SoTienTrenTietChuan'";
            a = (float)Convert.ToDouble(dataBaseAccess.excuteScalar(excuteString));
            return a;
        }

    }
}
